﻿// Program.cs
using NetTopologySuite.Features;
using NetTopologySuite.Geometries;
using System;

namespace Observer
{
    class Program
    {
        static void Main(string[] args)
        {
            // 创建原始要素：一个点几何和属性表
            var geometry = new Point(new Coordinate(1, 1));
            var attributes = new AttributesTable();
            attributes.Add("Name", "示例要素");
            var feature = new Feature(geometry, attributes);

            // 创建主题（目标）
            var subject = new FeatureSubject { Feature = feature };

            // 创建并注册观察者
            var mapObserver = new MapCanvasObserver();
            var attrObserver = new AttributeViewObserver();
            subject.Attach(mapObserver);
            subject.Attach(attrObserver);

            // 模拟修改几何：改变点的坐标
            feature.Geometry = new Point(new Coordinate(2, 2));
            subject.Status = ChangeStatus.GEOMETRY;
            subject.Notify(); // 触发观察者输出

            // 模拟修改属性：更新Name字段
            feature.Attributes["Name"] = "修改后的要素";
            subject.Status = ChangeStatus.ATTRIBUTE;
            subject.Notify(); // 触发观察者输出

            Console.ReadLine(); // 等待用户输入
        }
    }
}